<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<meta name="viewport" content="width=device-width, initial-scale=1.0">
		<title>pms项目管理系统后台</title>
		<link rel="stylesheet" href="css/core.css" />
		<link rel="stylesheet" href="css/menu.css" />
		<link rel="stylesheet" href="css/amazeui.css" />
		<link rel="stylesheet" href="css/component.css" />
		<link rel="stylesheet" href="css/page/form.css" />
		<script src="js/seo.js"></script>
	</head>
	<body>
		<div class="account-pages">
			<div class="wrapper-page">
				<div class="text-center">
	                <a href="index.html" class="logo"><span>Admin<span>to</span></span></a>
	            </div>
	            
	            <div class="m-t-40 card-box">
	            	<div class="text-center">
	                    <h4 class="text-uppercase font-bold m-b-0">Sign In</h4>
	                </div>
	                <div class="panel-body">
	                	<form method="post" class="am-form">
	                		<div class="am-g">
	                			<div class="am-form-group">
							      <input type="email" class="am-radius"  name="username" id="account" placeholder="Username">
							    </div>
							
							    <div class="am-form-group form-horizontal m-t-20">
							      <input type="password" class="am-radius" name="password" id="password" placeholder="Password">
							    </div>

							    <!--<div class="am-form-group ">
		                           	<label style="font-weight: normal;color: #999;">
								        <input type="checkbox" class="remeber"> Remember me
								    </label>
		                        </div>-->
		                        
		                        <div class="am-form-group ">
		                        	<button type="submit" id="submit" class="am-btn am-btn-primary am-radius" style="width: 100%;height: 100%;">Log In</button>
		                        </div>
		                        
		                        <!--<div class="am-form-group ">
		                        <a href="page-recoverpw.html" class="text-muted"><i class="fa fa-lock m-r-5"></i> Forgot your password?</a>
		                        </div>-->
	                		</div>

	                	</form>
							
	                </div>
	            </div>
			</div>
		</div>
	</body>
<script src="js/jquery-1.11.1.min.js"></script>
<script>
	$("form").submit(function () {
		if ($("#account").val() != "" && $("#password").val() != "") {
			//新接口的返回数据
            /*{
                "msg": "登录成功,前端页面跳转",
                "code": 200,
                "adminUser": {
                	"adminId": 1,
                    "username": "admin",
                    "password": "admin"
            	}
            }*/
            //旧接口的数据返回
			/*
			{
				"Users": {
					"id": 10,
					"username": "admin",
					"password": "D83367BE4EA33EC08B2D0FCF39E0C3E30730719152682904E56AE012",
					"phone": "",
					"email": ""
				},
				"message": "admin",
				"status": 200
			}
			 */
			ajax("admin/adminLogin.action", JSON.stringify({
				"username": $("#account").val(),
				"password": $("#password").val()
			}), login, error);
			$("#submit").html('登录 <i class="am-icon-spinner am-icon-pulse"></i>');
		}
		else {
			$("#submit").html('<i class="am-icon-times"></i> 账号&密码不能为空！');
			$("#submit").attr("class", "am-btn am-btn-lg am-fl am-btn-block am-btn-danger");
			setTimeout(function () {
				$("#submit").html("登 录");
				$("#submit").attr("class", "am-btn am-btn-primary am-btn-lg am-fl am-btn-block");
			}, 3000);
		}
		return false;
	})
	//ajax封装
	function ajax(url, data, success, error) {
		$.ajax({
			type: 'post',
			data: data,
			url: url,
			dataType: 'json',
			contentType: "application/json",
			success: function (d) {
				success(d);
			},
			error: function (e) {
				error(e);
			}
		});
	}
	function login(data) {
		console.info(data.message);
		if (data.code == 500) {
			$("#submit").html('<i class="am-icon-times"></i>账号或密码错误！');
			$("#submit").attr("class", "am-btn am-btn-lg am-fl am-btn-block am-btn-danger");
			setTimeout(function () {
				$("#submit").html("登 录");
				$("#submit").attr("class", "am-btn am-btn-primary am-btn-lg am-fl am-btn-block");
			}, 3000);
		} else {
			sessionStorage.username = data.adminUser.username;
//			pages/index.action
				location.href = "admin/index.action";
		}
	}

	function error(e) {
		console.error(e);
		alert("服务器错误！");
	}
</script>
</html>
